package com.huqing.icu.service.impl;

import com.huqing.icu.enums.FileStatusEnum;
import com.huqing.icu.mapper.ChatFileMapper;
import com.huqing.icu.model.ChatFile;
import com.huqing.icu.service.IUserFileService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Description 消息引用文件接口实现类
 * @Author huqing
 * @Date 2025/7/26 21:55
 **/
@Service
public class UserFileServiceImpl implements IUserFileService {

    /*@Autowired
    private VectorStore vectorStore;*/
    @Resource
    private ChatFileMapper userFileMapper;

    /**
     * 上传文件
     *
     * @param userId
     * @param fileList
     * @return
     */
    @Override
    public Long uploadFile(Long userId, List<MultipartFile> fileList) {

        for (MultipartFile file : fileList) {

            String fileName = file.getOriginalFilename();
            //获取文件后缀
            int doIndex = fileName.lastIndexOf(".");
            String fileType = fileName.substring(doIndex + 1);

            ChatFile userFile = new ChatFile();
            userFile.setUserId(userId);
            userFile.setFileName(fileName);
            userFile.setFileType(fileType);
            userFile.setFileSize(file.getSize());
            userFile.setStatus(FileStatusEnum.PENDING.getCode());
            //userFile.setTokenUsage();

            userFileMapper.insert(userFile);
        }


        return null;
    }
}
